//
//  SEGTarget_Navi.m
//  Commom
//
//  Created by 山刘 on 2019/4/15.
//  Copyright © 2019年 山刘. All rights reserved.
//

#import "SEGTarget_Navi.h"
#import "SEGBasicNavigationController.h"
#import "SEGWaitingViewController.h"

@implementation SEGTarget_Navi
-(UINavigationController*)segAction_initNavigationController:(NSDictionary*)params{
    if (params && [params isKindOfClass:[NSDictionary class]]  && [[params allKeys] containsObject:@"vc"] && [[params valueForKey:@"vc"] isKindOfClass:[UIViewController class]]) {
        return [[SEGBasicNavigationController alloc] initWithRootViewController: [params valueForKey:@"vc"]];
    }
    return [[SEGBasicNavigationController alloc] init];
}

/**
 * 给类包裹一层navigation
 * @author Sam
 */
-(UINavigationController*)segAction_getNaviController:(NSDictionary*)params{
    UINavigationController* navi = [self segAction_initNavigationController:params];
    navi.navigationBar.hidden = YES;
    return navi;
}

/**
 * 返回NavigationController类名
 * @author Sam
 */
-(NSString*)segAction_getNaviControllerStringClass:(NSDictionary*)params{
    return  NSStringFromClass(SEGBasicNavigationController.class);
}




/**
 初始化等待页面
 */
-(UIViewController*)segAction_initWaitingViewController:(NSDictionary*)params{
    return [[SEGWaitingViewController alloc]init];
}

/**
 * 获取app最顶层的控制器
 * @author Sam
 */
-(UIViewController*)segAction_getCurrentController:(NSDictionary*)params{
    UIViewController* vc = [UIApplication sharedApplication].delegate.window.rootViewController;
    while (1) {
        if ([vc isKindOfClass:[UITabBarController class]]) {
            vc = ((UITabBarController*)vc).selectedViewController;
        }
        
        if ([vc isKindOfClass:[UINavigationController class]]) {
            vc = ((UINavigationController*)vc).visibleViewController;
        }
        
        if (vc.presentedViewController) {
            vc = vc.presentedViewController;
        }else{
            break;
        }
    }
    return vc;
}
@end
